<?php

class ConfirmRequestManager
{
	public static function GenerateRequestURL($URL, $Param1 = '', $Param2 = '', $Param3 = '')
	{
		$bean = R::dispense('confirmrequest');
		
		$bean->request = RandomGenerator::GetString(16);
		while(R::findOne('confirmrequest', 'request=\'' . $bean->request . '\''))
			$bean->request = RandomGenerator::GetString(16);
		
		$bean->value = RandomGenerator::GetString(16);
		$bean->url = $URL;
		$bean->param1 =	htmlentities($Param1);
		$bean->param2 =	htmlentities($Param2);
		$bean->param3 =	htmlentities($Param3);
		
		R::store($bean);
		return $URL . '?key=' . $bean->request . '&value=' . $bean->value;
	}
	
	public static function GetRequest( $URL, $Key, $Value)
	{
		return R::findOne('confirmrequest', 'url=\'' . $URL . '\' and request=\'' . $Key . '\' and value=\'' . $Value . '\'');
	}
	
	public static function DeleteRequest( $Key )
	{
		if($bean = R::findOne('confirmrequest', 'request=\'' . $Key . '\''))
		R::trash( $bean );
	}
}